<template>
  <div class="workInfo">
    <base-table :tableSetting="baseTableSetting"></base-table>
  </div>
</template>

<script>
export default {
  props: {
    tableData: {
      type: Array,
      default: () => {
        return [];
      },
    },
    status: {
      type: Number,
    },
  },
  data() {
    return {
      baseTableSetting: {
        indexShow: true,
        column: [
          {
            label: "工作类型",
            prop: "workType",
            formatter: (row) => {
              return this.$store.getters.fineDirtDataName(
                "work_type_code",
                row.workType
              );
            },
          },
          {
            label: "编码",
            prop: "workCode",
          },
          {
            label: "内容",
            prop: "workContent",
          },
          {
            label: "时间",
            prop: "completionTime",
          },
        ],
        data: [],
        noBorderRight: false,
        autoHeight: true,
        rowClick: (row) => {
          this.openWorkDetail(row, row.workType);
        },
        //height: 400,
      },
    };
  },
  created() {},
  watch: {
    tableData: {
      handler(val) {
        this.init(val);
      },
      deep: true,
    },
  },
  methods: {
    //初始化
    init(val) {
      this.baseTableSetting.data = val.filter((item) => {
        return item.status == this.status;
      });
    },
    openWorkDetail(row, type) {
      switch (type) {
        case "workTicket":
          this.goDetailPage(row, "workTicketProcessingDetails", "edit");
          break;
        case "operationTicket":
          this.goDetailPage(row, "substationTicketDetails", "edit");
          break;
        case "defect":
          this.goDetailPage(row, "defectOrderDetails", "edit");
          break;
        case "maintain":
          this.goDetailPage(row, "normalMaintenanceDetails", "edit");
          break;
        case "overhaul":
          this.goDetailPage(row, "overhaulDetails", "edit");
          break;
        case "repair":
          this.goDetailPage(row, "overhaulDetails", "edit");
          break;
        case "experiment":
          this.goDetailPage(row, "experimentOrderDetails", "edit");
          break;
        case "patrol":
          this.goDetailPage(row, "patrolOrderDetails", "edit");
          break;
        default:
          this.goDetailPage(row, "overhaulApplicationDetails", "edit");
          break;
      }
    },
    //跳转到详情页
    goDetailPage(row, router, type) {
      const { href } = this.$router.resolve({
        name: router,
        query: {
          val: router == "workTicketProcessingDetails" ?row.workId : "",
          id: row.workId ? row.workId : "",
          pageType: type ? type : "",
        },
      });
      window.open(href, "_blank");
    },
  },
};
</script>

<style lang="less" scoped>
.workInfo {
  width: 100%;
  height: 100%;
}
</style>